# todo 这是知识图谱生成视图
from flask import request
from utils import Graphrag
from common import ApiResponse
from common.BaseResponse import BaseResponse
from common.BaseResponse import ErrorCode
import asyncio

# todo 生成知识图谱
def generate():
    return "知识图谱生成视图"


def rag():
    question = request.args.get("question")
    try:
        result = asyncio.run(Graphrag.Rag.local(query=question))
        print(result)
        return ApiResponse.ApiResponse.success(data=result)
    except Exception as e:
        error_response = BaseResponse.from_error_code(ErrorCode.OPERATION_ERROR)
        return ApiResponse.error(code=error_response.code, message=error_response.message)

